package com.xiaoying.server.publish.servlet;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xiaoying.server.publish.utils.CommonHelper;


public class LoadServlet extends HttpServlet {


    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static Log log = LogFactory.getFactory().getInstance(LoadServlet.class);
    
    private String configFile ;

	public void init(ServletConfig cfg) throws ServletException {
	    super.init(cfg);
		configFile = cfg.getServletContext().getRealPath("WEB-INF") 
		             + System.getProperty("file.separator") 		//获取路径的符号/或者\(和系统有关)
		             + cfg.getInitParameter("configFile");
		CommonHelper.APPPATH = cfg.getServletContext().getRealPath("WEB-INF");
		startServer();
	}

	public void startServer() {
	    log.info("XiaoYing视频发布程序启动...");
		try {
		    Dispatcher dispatcher = Dispatcher.getInstance();
            dispatcher.init(configFile);
            dispatcher.startup();
			System.out.println("--->start server");
        } catch (Exception e) {
            log.error("启动异常。",e);
            e.printStackTrace();
        }		
		log.info("XiaoYing视频发布程序启动成功。");
	}
}
